# def func():

#     print("呵呵")
# print(func)
#
# a = func
# a()
# print(a)

# def func1():
#     print("呵呵")
# def func2():
#     print("呵呵")
# def func3():
#     print("呵呵")
# def func4():
#     print("呵呵")
#
# lst = [func1,func2,func3,func4]
# for i in lst:
#     i()

# def func():
#     print("吃了么")
# def func2(fn):
#     print("我是func2")
#     fn()
#     print("我是func2")
# func2(func)
# def func1():
#     print("123")
#     def func2():
#         print("456")
#     print("123")
#     return func2
# fn = func1()
# fn()
# 闭包就是内层函数，对外层函数（非全局）的变量的引用
#可以使用__closure__来检测函数是否是闭包，返回cell就是闭包，返回none就不是闭包
# def func1():
#     name = "lys"
#     def func2():
#         print(name)
#     func2()
#     print(func2.__closure__)
# func1()
# from urllib.request import urlopen
# def but():
#     content = urlopen("https://www.loveplay.top/").read()
#     def get_content():
#         return content
#     return get_content
# fn = but()
# content = fn()
# print(content)
# content2 = fn()
# print(content2)

#综上，闭包的作用就是让一个变量能够常驻内存，供后面的程序使用
#使用while循环+迭代器来模拟for循环
# lst = [1,2,3]
# lst_iter = lst.__iter__()
# while True:
#     try:
#         i = lst_iter.__next__()
#         print(i)
#     except StopIteration:
#         break

